package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.Department;
import com.olddriver.crm.mapper.DepartmentMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService{

    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public int insert(Department department){
        return departmentMapper.insert(department);
    }

    @Override
    public int update(Department department){
        return departmentMapper.update(department);
    }

    @Override
    public List<Department> listAll() {
        return departmentMapper.find();
    }

    @Override
    public PageResult query(QueryObject qo) {
        int total = departmentMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, departmentMapper.queryRows(qo));
    }

    @Override
    public void updateState(Boolean state, Long id) {
        departmentMapper.updateState(state,id);
    }
}
